import pytest,requests,os


@pytest.fixture(scope='function')

def login_token():
    # 请求地址
    url='http://10.59.9.18/small/user/v1/login'
    # 请求体
    data={
        'phone':'13811033965',
        'pwd': '123456Aa'
    }
    # post请求方法
    r=requests.post(url=url,json=data)
    r_json=r.json()
    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['sessionId'])
    # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['sessionId']


@pytest.fixture(scope='function')
# 新闻热点
def login_token2():
    # 请求地址
    url='http://10.59.9.18/hotNews/user/v1/login'
    # 请求体
    data={
        'userName':'1234567890',
        'passwd': '1234567890'
    }
    # post请求方法
    r=requests.post(url=url,json=data)
    r_json=r.json()
    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['token'])

    # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['token']


@pytest.fixture(scope='function')

def login_token3():
    # 请求地址
    url='http://10.59.9.18/movieApi/user/v2/login'
    # 请求体
    data={
        'email':'1478997572@qq.com',
        'pwd': 'eWLPHopE945d2ivttHaQTQ=='
    }
    # post请求方法
    r=requests.post(url=url,params=data)
    r_json=r.json()
    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['sessionId'])
    # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['sessionId']


@pytest.fixture(scope='function')

# 维度科技
def login_token4():
    # 请求地址
    url='https://10.59.9.18/techApi/user/v1/login'
    # 请求体
    data={
        'phone':'13784554160',
        'pwd': 'S0hBZElnMkExQml6T21vYVRacVNmN2lSRHUxNGVsK2JMSXlBUkpWSmJsM0JJYkN0M0RYaTZLMDh0N3pLSU1FYzgvR1FFZzhZMExYaXFqNWE1WlBiUGd4bWdYWFVvZ09VTzdYcmpZOUZRRStqUkhqN1RVc25GSDJvaWp1STI3Tm1WdWpDdlRZTUpGVit5WGRMOTZlZlY3eTlKWVJENzlIdzlPN2xNMWQ5eUEwPQ=='
    }
    # post请求方法
    r=requests.post(url=url,params=data,verify=False)
    r_json=r.json()

    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['sessionId'])
    # # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['sessionId']


# 约车
@pytest.fixture(scope='function')
def login_token5():
    # 请求地址
    url='http://10.59.9.18/car-user/user/v1/login'
    # 请求体
    data={
        'userName':'zhangsan',
        'passwd': '123456'
    }
    # post请求方法
    r=requests.post(url=url,json=data)
    r_json=r.json()

    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['token'])
    # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['token']


# 维度健康
@pytest.fixture(scope='function')
def login_token6():
    # 请求地址
    url='http://10.59.9.18/health/user/v1/login'
    # 请求体
    data={
        'email':'1013052834@qq.com',
        'pwd': 'lZjdXyj15cOhn1a0yJKsW7o+fw/ogBDzn6CcyPSJUVIMmCPtCs+zuPwh7IZkXZiRhJvvjdIz9D2z1jkMOtD/36ddaLFMtQd9xIk0jAaDP1TH/lEHvvUPwot6asMGMGkH9EgBPT+4eaYC77BGQBPOASweQZE5KDF8BeN/c0sLfSw='
    }
    # post请求方法
    r=requests.post(url=url,params=data)
    r_json=r.json()

    # 打印要提取的值
    print(r_json['result']['userId'])
    print(r_json['result']['sessionId'])
    # 提取userId和sessionId
    yield r_json['result']['userId'],r_json['result']['sessionId']


# A3mall
@pytest.fixture(scope='function')
def login_token7():
    # 请求地址
    url='http://10.59.9.14:7003/api/public/login'
    # 请求体
    data={
        'password':"123456",
        'username':"17601535724"
    }
    # post请求方法
    r=requests.post(url=url,json=data)
    r_json=r.json()

    # 打印要提取的值
    token = 'Bearer ' + r_json['data']['token']
    print(r_json['data']['token'])
    # 提取userId和sessionId
    yield token